package cc.rengu.igas.cops.core.service.trans.payment;

import cc.rengu.igas.cops.common.enums.RespCodeEnum;
import cc.rengu.igas.cops.core.service.base.ManageService;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.service.common.constant.TreeNodeConstant;
import cc.rengu.oltp.service.model.BizResponse;
import cc.rengu.oltp.service.model.ImageCodeResult;
import cc.rengu.oltp.service.realize.ImageCodeService;
import cc.rengu.oltp.service.realize.impl.ImageCodeServiceImpl;
import cc.rengu.oltp.utility.util.XmlTreeUtil;

public class CopsGenImageAuthCodeService extends ManageService {
    @Override
    protected Object bizBeforeCust() throws Exception {
        return null;
    }

    @Override
    protected BizResponse bizProcessCust(Object request) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String instId = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.HEADER_INST_ID);
        String sysSeqNum = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.SYS_SEQ_NUM);

        ImageCodeService imageCodeService = new ImageCodeServiceImpl();
        ImageCodeResult imageCodeResult = imageCodeService.applyImageCode(instId, sysSeqNum, null);

        rglog.debug("图片验证码：<{}>", imageCodeResult.getResult());
        xmlTreeUtil.setXmlTreeStringValue("authCodeImage", (String) imageCodeResult.getResult());
        xmlTreeUtil.setXmlTreeStringValue("authCodeSeqNum", sysSeqNum);

        BizResponse<Object> bizResponse = new BizResponse<>();
        bizResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        bizResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
        bizResponse.setRspSysId(AppParamConstant.SYS_ID);
        return bizResponse;
    }

    @Override
    protected void bizAfterCust(Object response) throws Exception {

    }
}
